package com.tianji.promotion.handler;

import com.tianji.common.utils.NumberUtils;
import com.tianji.promotion.service.ICouponService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @description
 * @author: ZXX-挚爱
 * @time: 2023/8/2 20:50
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class CouponJobHandler {
    private final ICouponService couponService;
    @XxlJob("couponIssueJobHandler")
    public void handleCouponIssueJob(){
        // 1.获取分片信息，作为分页信息
        int page = XxlJobHelper.getShardIndex();
        String param = XxlJobHelper.getJobParam();
        int size = NumberUtils.parseInt(param);
        log.info("开始定时发放优惠券");
        couponService.issueCouponByPage(page,size);
    }
}
